/*
 * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: CC0-1.0
 */

#include <stdio.h>
#include "nvs.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "led.h"
#include "key.h"
#include "rs485.h"
#include "spp.h"
#include "slave.h"
#include "nvs_app.h"
#include "sgm.h"
#include "wifi_sta.h"

extern led_obj_t* led1_obj;

void app_main(void)
{
    sgm_app_main();
    nvs_app_main();
    wifi_app_main();
    slave_app_main();
    led_app_main();
    BSP_GPIO_KEY_INIT(BSP_GPIO_KEY1);
    if(BSP_GPIO_KEY_LEVEL(BSP_GPIO_KEY1))
    {
        //透传模式
        //key_app_main();
        spp_app_main();
        rs485_app_main();
    }
    else
    {
        //1、提示灯闪烁
        led_ctrl(led1_obj, LED_BLINK);
        //2、松手进入设置模式
        while(1)
        {
            if(BSP_GPIO_KEY_LEVEL(BSP_GPIO_KEY1))
            {
                break;
            }
            vTaskDelay(100 / portTICK_PERIOD_MS);
        }
        //3、设置模式
        rs485_set_mode(1);
        spp_set_mode(1);
        key_app_main();
        spp_app_main();
        rs485_app_main();
    }
    //休眠
    vTaskDelay(portMAX_DELAY);
}
